package com.fieldchain.ex.fa100.utils.net.common;

import com.fieldchain.ex.fa100.access.Constant;
import com.fieldchain.ex.fa100.access.MyApplication;
import com.fieldchain.ex.fa100.bean.event.BaseEvent;
import com.fieldchain.ex.fa100.utils.net.access.HttpRequest;
import com.fieldchain.ex.fa100.utils.net.modle.StringRequest;
import com.fieldchain.ex.fa100.utils.net.tools.NetStatus;
import com.fieldchain.ex.fa100.utils.screen.MyToast;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/11
 */
public class EmailCode {
    private static EmailCode emailCode;
    public static EmailCode getInstance(){
        if(null==emailCode){
            emailCode=new EmailCode();
        }
        return emailCode;
    }
    public void getEmail(String em,String imgCode){
        if(em.length()==0){
            MyToast.show("请输入邮箱");
            stop();
            return;
        }
        if(imgCode.length()==0){
            stop();
            MyToast.show("请输入图形验证码");
            return;
        }
        if(!NetStatus.isNetWorkConnected(MyApplication.getAppContext())){
            stop();
            MyToast.show("网络连接失败");
            return;
        }
        HashMap map=new HashMap();
        map.put("email",em);
        map.put("imgCode",imgCode);
        map.put("apiName","");
        HttpRequest.getInstance().getRequest(map, Constant.emailCode,"null",new StringRequest() {
            @Override
            public void onSucess(String str, int code, String msg) {
                MyToast.show(msg);
                if(code!=200)stop();
            }

            @Override
            public void onFaild(Exception e) {
                stop();
            }
        });
    }
    public void stop(){
        EventBus.getDefault().post(new BaseEvent(3));
    }
}
